package com.controller;

import com.model.jpa.Player;
import com.service.PlayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "player")
public class PlayerController {

    @Autowired
    private PlayerService playerService;

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public Player add(@RequestBody Player player) {
        if (player != null) {
            playerService.save(player);
        }
        return null;
    }

    @RequestMapping(value = "findAll", method = RequestMethod.GET)
    public Page<Player> findAll() {
        Pageable pageable = new PageRequest(0,10);
        return playerService.findPage(pageable);
    }

}
